package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import service.HelloWorldService;

@Controller
public class HelloWorldController {
    String message = "Welcome to Spring MVC!";
    
    private HelloWorldService helloWorld;

    @RequestMapping("/hello")
    public ModelAndView showMessage(@RequestParam(value = "name", required = false, defaultValue = "World") String name) {
	System.out.println("in controller");
	System.out.println("param: " + name);
	ModelAndView mv = new ModelAndView("helloworld");
	mv.addObject("message", message);
	mv.addObject("name", helloWorld.getMessage(name));
	return mv;
    }

    public void setHelloWorld(HelloWorldService helloWorld) {
	this.helloWorld = helloWorld;
    }
}